home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 408 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.3 KB  |  74 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: Ian T Zimmerman <itz@rahul.net>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Correctness of compilers behavior
  5. Date: 20 Feb 1996 10:42:51 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <199602180416.UAA01735@kronstadt.rahul.net>
  9. References: <3122157A.2EB2@orbotech.co.il> <4g3i93$9lp@mulga.cs.mu.OZ.AU>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Sat, 17 Feb 1996 20:16:45 -0800
  12. In-Reply-To: fjh@munta.cs.mu.OZ.AU's message of 18 Feb 1996 02:14:25 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMSoWOEy4NqrwXLNJAQE7sgH+NVfdt7WC1BcIQLoPWa8sulrXIImqs1SJ
  15.     sf5XF42ZrkayRxvjqPZwDtU/U2hwS3GSWZL9R2ma6cg8WdLIJn1IRg==
  16.     =kqze
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article <4g3i93$9lp@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU
  20. (Fergus Henderson) writes:
  21.  
  22. > "Constantine Antonovich:" <const@Orbotech.Co.IL> writes:
  23. > >  for (unsigned i=0; i<size; ++i) {
  24. > >    (bptr+i)->~B();
  25. > >    new(aptr+i) A;
  26. > >  }
  27. > >
  28.  
  29. > >int main(void)
  30. > >{
  31. > >  A* arr=foo(2);
  32. > >  delete [] arr;
  33. > This has undefined behaviour.  It contravenes 5.3.5[expr.delete]/2, which
  34. > says that the expression passed to `delete []' must be a pointer to the
  35. > first element of an array of objects allocated with `new []'; this is not
  36. > the case, because although there once was such an array at that memory
  37. > location, its lifetime ended when the memory was overwritten by the calls
  38. > to placement new (see 3.8[basic.life]/1).
  39.  
  40. Is it relevant here that A and B are unrelated classes? What about the
  41. following code?
  42.  
  43. A a;
  44.  
  45. A* as = new A [10];
  46.  
  47. for (int i = 0; i < 10; ++i) {
  48.     new (&as[i]) A(a);
  49. }
  50. delete [] as;
  51.  
  52. If this is undefined, how else can I initialize array members with a
  53. nondefault constructor?
  54.  
  55. Thanks in advance,
  56.  
  57. -- 
  58. Ian T Zimmerman            +-------------------------------------------+
  59. P.O. Box 13445             I    With so many executioners available,   I
  60. Berkeley, California 94712 I suicide is a really foolish thing to do.  I
  61. USA  <itz@rahul.net>       +-------------------------------------------+
  62. ---
  63. [ To submit articles: Try just posting with your newsreader.  If that fails,
  64.                       use mailto:std-c++@ncar.ucar.edu
  65.   FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  66.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  67.   Comments? mailto:std.c++-request@ncar.ucar.edu 
  68. ]
  69.